#pragma once
#include<iostream>
#include<assert.h>
#include<vector>
using namespace std;
namespace zjw 
{  
	template<class T>
	class vector
	{
	public:
		typedef	 T* iterator;

		vector()
			:_start(nullptr)
			,_finish(nullptr)
			,_end_of_storage(nullptr)
		{


		}
		iterator begin()  const
		{
			return _start;
		
		
		}
		iterator end()  const
		{

			return _finish;


		}
		size_t capacity()  const
		{
			return _end_of_storage-_start;
		
		
		
		}
		size_t size()  const
		{
			return _finish - _start;
		
		}
		bool empty()
		{
			return _finish == _start;
		
		}
		T& operator[](size_t pos)  const
		{
			assert(pos < size());
				return _start[pos];
		
		}
		void reserve(size_t n)
		{
			if (n > capacity())
			{
				int sz = size();
				T* tmp = new T[n];
				if (_start)
				{
					memcpy(tmp, _start, sizeof(T) * n);
					delete[] _start;
				}
				_start = tmp;
				_finish = _start + sz;
				_end_of_storage = _start + n;




			}
	    }
		void push_back(const T& x)
		{
			if (_finish == _end_of_storage)
			{
				reserve(capacity() == 0 ? 4 : capacity() * 2);

			}
			*_finish = x;
			_finish++;



		
		
		
		
		
		
		
		}
		void pop_back()
		{
			assert(!empty());
			--_finish;
		

		}
		void resize(size_t n,T val=T())
		{
			if (n < capacity())
			{
				_finish = _start + n;

			}
			else
			{
				reserve(n);
				while (_finish != _end_of_storage)
				{
					*_finish = val;
					_finish++;
				}





			}
		
		
		
		
		
		
		
		}
		void func(const vector<int>& v)
		{
			for (int i = 0; i < v.size(); i++)
			{  
				cout << v[i] << " ";





			}
			cout << endl;
			vector<int>::iterator it = v.begin();
			while (it != v.end())
			{

				cout << *it << " ";
				it++;


			}
			for (auto e : v)
			{
				cout << e << " ";





			}
			cout << endl;









		}
		void insert(iterator pos, const T& val)
		{
			assert(pos >= _start);
			assert(pos <= _finish);
			if (_finish == _end_of_storage)
			{
				int len = pos - _start;
				reserve(capacity() == 0 ? 4 : capacity() * 2);
				pos = _start + len;
			}
			iterator end = _finish - 1;
			while (end >=pos)
			{
				*(end + 1) = *end;
				end--;
            }
			*pos = val;
			_finish++;

		}
		void earse(iterator pos)
		{
			assert(pos != _finish);
			iterator end = pos + 1;
			while (end != _finish)
			{
				*(end - 1) = *end;
				++end;

			}
			--_finish;
			(*pos)++;
		}









	private:
		iterator _start;
		iterator _finish;
		iterator _end_of_storage;















	};
	
	void test1()
	{
		vector<int>res;
		res.push_back(1);
		res.push_back(2);
		res.push_back(3);
		res.push_back(4);
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";




		}
		cout << endl;
		res.pop_back();
		res.pop_back();
		vector<int>::iterator it = res.begin();
		while (it != res.end())
		{
			cout << *it << " ";
			it++;






		}
		cout << endl;


	
	
	
	
	
	
	
	
	}
	void test2()
	{
		vector<int>res;
		res.push_back(1);
		res.push_back(2);
		res.push_back(3);
		res.push_back(4);
			for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";




		}
			cout << endl;
			res.resize(10);

			for (int i = 0; i < res.size(); i++)
			{
				cout << res[i] << " ";
			}
			cout << endl;
			res.resize(1);
			for (int i = 0; i < res.size(); i++)
			{
				cout << res[i] << " ";
			}
	
	
	
	
	
	}
	void test3()
	{
		vector<int>res;
		res.push_back(1);
		res.push_back(2);
		res.push_back(3);
		res.push_back(4);
		res.func(res);
	
	
	
	
	
	
	}
	void test4()
	{
		vector<int>res;
		res.push_back(1);
		res.push_back(2);
		res.push_back(3);
		res.push_back(4);
		//res.push_back(5);
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";
		}
		cout << endl;
		auto pos = find(res.begin(), res.end(),2);
		if (pos != res.end())
		{
			res.insert(pos, 1000);




		}
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";
		}
		cout << endl;


	
	
	
	
	
	}
	void test5()
	{
		std::vector<int>res;
		res.push_back(1);
		res.push_back(2);
		res.push_back(3);
		res.push_back(4);
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";
		}
		cout << endl;
		auto pos = find(res.begin(), res.end(), 2);
		if (pos != res.end())
		{
			res.erase(pos);




		}
		
		for (int i = 0; i < res.size(); i++)
		{
			cout << res[i] << " ";
		}
		cout << endl;
	   
	
	
	}
























}
[["X", "X", "X", "X"]
 ["X", "O", "O", "X"]
 ["X", "X", "O", "X"]
 ["X", ".", "X", "X"]



  ["X", "X", "X", "X"]
  ["X", "X", "X", "X"]
  ["X", "X", "X", "X"]
  ["X", "O", "X", "X"]
